//
//  HWtuiguanpanhangbangViewController.m
//  HWPromoteProjectAPP
//
//  Created by 陈道斌 on 2020/3/6.
//  Copyright © 2020 陈道斌. All rights reserved.
//

#import "HWtuiguanpanhangbangViewController.h"
#import "HWtuiguanpanhangbangCell.h"
#import "HWDividedIntoViewController.h" // 分成提现
#import "HWtuiguanpanhangModel.h"
@interface HWtuiguanpanhangbangViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UIView *beijingView;
@property (weak, nonatomic) IBOutlet UILabel *leijirenshuLabel;
@property (weak, nonatomic) IBOutlet UILabel *jingerLabel;
@property (strong,nonatomic) NSDictionary *MyDic;

@property(strong,nonatomic) UITableView *mainaTableVie;
@property(strong,nonatomic) UIView *headerView;
@property(strong,nonatomic) NSMutableArray *dataMuArr;





@end

@implementation HWtuiguanpanhangbangViewController

-(UITableView *)mainaTableVie {
    
    if  (_mainaTableVie == nil) {
        
        _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(20, NavBarHeight + 68+122, kScreenW-40, kScreenH-NavBarHeight-68-122) style:UITableViewStylePlain];
        // _mainaTableVie = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-44) style:UITableViewStylePlain];
     //   _mainaTableVie.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
        _mainaTableVie.delegate = self;
        _mainaTableVie.dataSource = self;
        _mainaTableVie.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainaTableVie.backgroundColor = beijingyanSe;
        _mainaTableVie.layer.cornerRadius = 12;
        _mainaTableVie.layer.masksToBounds = YES;
    
       // _mainaTableVie.backgroundColor = [UIColor whiteColor];
    }
    
    
    return   _mainaTableVie;
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 设置常用的属性
    [self setCommonProperties];
    
    [self setupUI];
    [self addheaderView];
    
    //发送网路请求
    [self sendNetworkRequest];
    
    
    
}
- (void)addheaderView {
    
    
    self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 44+34)];
    UILabel   *userLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, kScreenW - 40, 34)];
    userLabel.text = @"推广榜";
    userLabel.textAlignment =  NSTextAlignmentCenter;
    userLabel.textColor = [UIColor whiteColor];
  //  userLabel.alpha = 0.85;
    userLabel .font = [UIFont systemFontOfSize:12];
    userLabel.numberOfLines = 1;
    userLabel.backgroundColor = RGB(22, 190, 173);
    [self.headerView addSubview:userLabel];
    
    CGFloat W = kScreenW - 40;
    CGFloat H = 44;
    CGFloat meigelabeW = W / 3;
    
    NSArray *dataArr = @[@"排行榜",@"用户",@"收益"];
    
    
    
    
    
    
    for (int i = 0 ; i < 3; i++) {

             UILabel   *userLabel = [[UILabel alloc]initWithFrame:CGRectMake(meigelabeW*i, 34, meigelabeW, H)];
             userLabel.text = dataArr[i];
             userLabel.textAlignment =  NSTextAlignmentCenter;
             userLabel.textColor = RGB(0, 0, 0);
             userLabel.alpha = 0.85;
             userLabel .font = [UIFont systemFontOfSize:12];
             userLabel.hidden = NO;
            //  userLabel.backgroundColor = RGB(255, 255, 255);
             userLabel.backgroundColor =  [UIColor whiteColor];
             userLabel.numberOfLines = 2;
             [ self.headerView   addSubview: userLabel];
    
           
       }
    
      for (int i = 0 ; i < 3; i++) {

          UIView *fengexian = [[UIView alloc]initWithFrame:CGRectMake(i*meigelabeW, 34, 1, H)];
          fengexian.backgroundColor = RGB(232, 232, 232);
          [self.headerView addSubview:fengexian];
        
         
          
      }
    
    
      UIView *fengexian =  [[UIView alloc]initWithFrame:CGRectMake(0, 34+43, W, 1)];
      fengexian.backgroundColor = RGB(232, 232, 232);
      [self.headerView addSubview:fengexian];
    
    
      self.mainaTableVie.tableHeaderView  =  self.headerView;
    
    
    
    
    
    
    
}




- (void)setCommonProperties {
    
    self.navigationItem.title = @"推广排行";
    self.view.backgroundColor = beijingyanSe;
    
    self.beijingView.layer.cornerRadius = 12;
    self.beijingView.layer.masksToBounds = YES;
    
    
    
    
}


// 设置UI
- (void)setupUI {
    
    
    [self.view addSubview:self.mainaTableVie];
    [self.mainaTableVie mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.top.mas_equalTo(68+122);
        make.bottom.mas_equalTo(0);
    }];
    
}


// 发送网络请求
- (void)sendNetworkRequest {
    
    
    
     
         NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
         NSString *uid =  [HWLocallyStoredData getLoginUserID];
         NSString *signStr = [NSString stringWithFormat:@"%@%@%@",uid,tStr,@"adesxloksy13s98adv"];
         NSString  *signStrMd5  =   [WMUtil md5HexDigest:signStr];
         NSDictionary *parametes = @{      @"ios" : @"1",
                                      @"ct" : @"app",
                                        @"ac" : @"paihang",
                                        @"t" : tStr,
                                        @"uid":uid,
                                        @"sign" :signStrMd5
                                        };
        
        
            [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
                  
                 

                  NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
                  if ([codeStr intValue] == 1) {
                 
                         NSLog(@"%@",response);
                          
                      self.MyDic =   response[@"data"][@"my"];
                      
                      
                       self.dataMuArr = [HWtuiguanpanhangModel  mj_objectArrayWithKeyValuesArray:response[@"data"][@"list"]];
                      
                      [self.mainaTableVie reloadData];
                    
                      [self shuxingshezhishuju];
                      
                      
//                      self.dataMutableArr =   [response[@"data"] mutableCopy];
//                      [self.mainTabelView reloadData];
//                      
                      
                      
                      
                       
                  } else {
                      
                    [MBProgressHUD showError:response[@"message"]];
                                    
                
                      
                  }
                  
             
                  
              } failure:^(NSString *error) {
                 // [SVProgressHUD dismiss];
                  
                   [MBProgressHUD showSuccess:@"登录失败"];
                  [MBProgressHUD hideHUD];
                  
                  
              }];
        
    
    
    
    
    
    
    
}


//刷新数据
- (void)shuxingshezhishuju {
    
    
    self.leijirenshuLabel.text = [NSString stringWithFormat:@"%@",self.MyDic[@"num"]];
    self.jingerLabel.text =  [NSString stringWithFormat:@"%@",self.MyDic[@"money"]];
    
    
    
    
}




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    
    
   //  return 30;
    return self.dataMuArr.count;
    
    
    
    
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellID = @"cellID";
    
    HWtuiguanpanhangbangCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    if (!cell) {
        cell = [[HWtuiguanpanhangbangCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.selectionStyle =  UITableViewCellSelectionStyleNone;
     
    
    
     HWtuiguanpanhangModel *model =   self.dataMuArr[indexPath.row];
     cell.dijige = indexPath.row;
     cell.model = model;
    
     
    return  cell;
    
    
}




- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return  44;
    
    
    
}








- (IBAction)tuiguanmingxi:(UIButton *)sender {
    
    HWDividedIntoViewController *DividedInto = [[HWDividedIntoViewController alloc]init];
    [self.navigationController pushViewController:DividedInto animated:YES];
    
}





@end
